<?php if(count($hmenu)){ ?>
<div id="hmenu-container">
    <div class="hmenu-main">
        <div class="nav-left"></div>
        <div class="nav">
            <ul class="hmenu">
        <?php
        foreach($hmenu as $key =>$list)
        {
            $parentClass = '';
            $titlelink = $list['title'];
            
            if($list['segment'] == 'index'){ 
                $url = '/';
                $parentClass = 'first';
                $titlelink = "&nbsp;";
            }
            else if($list['segment'] == '#')
            { 
                $url = base_url().uri_string().'?#';
            }
            else { $url = 'page/'.$list['segment'];}
            $submenu = $this->MPage->getActiveSubPagesById($list['page_id']);
            if(count($submenu))
            {
                $parentClass = 'parent-li';
            }
            
            echo '<li class="'.$parentClass.'">';
            echo anchor($url, $titlelink);
            if(count($submenu))
            {
                echo '<ul class="submenu">';
                foreach($submenu as $subkey =>$item)
                {
                    $subchild = $this->MPage->getActiveSubPagesById($item['page_id']);
                    $subparClass = '';
                    if(count($subchild))
                    {
                        $subparClass = 'subpar-li';    
                    }
                    if($item['segment'] == '#')
                    { 
                        echo '<li class="'.$subparClass.'"><a>' . $item['title']. '</a>';
                    }else {
                        echo '<li class="'.$subparClass.'">' . anchor('page/'.$item['segment'], $item['title']);
                    }
                    if(count($subchild))
                    {
                        echo '<ul class="subchild">';
                        foreach($subchild as $childkey =>$child)
                        {  
                            if($child['segment'] == '#')
                            { 
                                echo '<li class="'.$subparClass.'"><a>' .$child['title']. '</a>';
                            }else {
                                echo '<li>' . anchor('page/'.$child['segment'], $child['title']).'</li>';
                            }      
                        }
                        echo '</ul>';        
                    }
                    echo '</li>';   
                }
                echo '</ul>';   
            }
            echo '</li>';    
        }
        ?>
            </ul>
        </div>
        <div class="nav-right"></div>
    </div>
</div>
<?php } ?>